﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace Socket服务器
{
    /// <summary>
    /// RestartWindow.xaml 的交互逻辑
    /// </summary>
    public partial class RestartWindow : Window
    {
        public RestartWindow(Exception  msg)
        {
            InitializeComponent();
            DT = new DispatcherTimer();
            DT.Tick += DT_Tick;
            DT.Interval = new TimeSpan(0, 0, 1);
            DT.Start();
            timer.Content = string.Format("正在关闭端口，{0}秒后程序重新启动", TimerCount.ToString());
            errormsg.Text  = LogException.ExceptionString(msg);
        }

        private void DT_Tick(object sender, EventArgs e)
        {
           if(TimerCount>0 )
            {
                TimerCount--;
                timer.Content = string.Format("正在关闭端口，{0}秒后程序重新启动", TimerCount.ToString());
            }
           else
            {
                DT.Stop();
                this.Close();
            }

        }
        /// <summary>
        /// 3秒倒计时
        /// </summary>
        int TimerCount = 1;
        DispatcherTimer DT;
    }
}
